package com.inepex.inechart.client.axes;

import java.util.ArrayList;
import java.util.TreeMap;

import com.inepex.inechart.shared.CartesianException;
import com.inepex.inechart.shared.axes.Axis;
import com.inepex.inechart.shared.axes.Tick;
import com.inepex.inegraphics.shared.GraphicalObjectContainer;
import com.inepex.inegraphics.shared.gobjects.GraphicalObject;
import com.inepex.inegraphics.shared.gobjects.Text;

/**
 * Class for assisting axis representation, and storing related properties/fields.
 * 
 * @author Miklós Süveges / Inepex Ltd.
 *
 */
public class AxisPresenterAssist {

	//model
	protected Axis axis;
	protected Axis perpAxis;
	/**
	 * [from,to] the actual interval
	 */
	protected double from;
	protected double to;
	
	//view
	protected double[] mergedTickPaddings;
	protected double[] axisStartCoord;
	protected double[] axisEndCoord;
	
	protected GraphicalObject axisLine;
	protected GraphicalObjectContainer tickLines;
	protected GraphicalObjectContainer gridLinesAndFills;
	protected GraphicalObjectContainer texts;
	
	protected TreeMap<Tick, Text> tickTextMap;
	
	//incremental progress assist 
	protected ArrayList<Tick> ticksToCalc;
	protected int totalTickCount;
	protected int calcedTickCount;
	
	public AxisPresenterAssist(Axis axis) {
		this.axis = axis;
		tickTextMap = new TreeMap<Tick, Text>();
		ticksToCalc = new ArrayList<Tick>();
		tickLines = new GraphicalObjectContainer();
		gridLinesAndFills = new GraphicalObjectContainer();
		texts = new GraphicalObjectContainer();
	}
	
	protected void checkPerpAxis(boolean throwException) throws CartesianException{
		if(perpAxis == null){
			perpAxis = axis.getPerpendicularAxis();
			if(perpAxis == null){
				throw new CartesianException();
			}
		}
	}

	public Axis getAxis() {
		return axis;
	}

	public Axis getPerpAxis() {
		return perpAxis;
	}

	public double getFrom() {
		return from;
	}

	public double getTo() {
		return to;
	}

	public double[] getMergedTickPaddings() {
		return mergedTickPaddings;
	}

	public double[] getAxisStartCoord() {
		return axisStartCoord;
	}

	public double[] getAxisEndCoord() {
		return axisEndCoord;
	}

	public GraphicalObject getAxisLine() {
		return axisLine;
	}

	public GraphicalObjectContainer getTickLines() {
		return tickLines;
	}

	public GraphicalObjectContainer getGridLinesAndFills() {
		return gridLinesAndFills;
	}

	public GraphicalObjectContainer getTexts() {
		return texts;
	}

	public TreeMap<Tick, Text> getTickTextMap() {
		return tickTextMap;
	}

	public ArrayList<Tick> getTicksToCalc() {
		return ticksToCalc;
	}

	public int getTotalTickCount() {
		return totalTickCount;
	}

	public int getCalcedTickCount() {
		return calcedTickCount;
	}
	
	
	
}
